import com.comdefinition.ApplicationRun
import com.comdefinition.cache.MsgCodeCache
import com.comdefinition.constant.CodeConstant
import com.comdefinition.modals.BaseRes
import com.comdefinition.utils.DateUtil
import com.fasterxml.jackson.databind.ObjectMapper
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

/**
 * Created by hp4664 on 2017/9/6.
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ApplicationRun.class)
class cdemoTest extends GroovyTestCase {

    @Test
    void test1() {
        ObjectMapper om = new ObjectMapper()
        String jonsStr = om.writeValueAsString(new BaseRes(resCode: CodeConstant.ERROR_9999.code))

        println "===========CodeConstant=======" + jonsStr
//        println "0000 "+CodeConstant.getDescByCode("0000")
//        println "9000 "+CodeConstant.getDescByCode("9000")
//        println "9001 "+CodeConstant.getDescByCode("9001")
//        println "5001 "+CodeConstant.getDescByCode("5001")

        println "============MsgCodeCache========="
        println "5001 " + MsgCodeCache.getMessageDesc("5001")
        println "9000 " + MsgCodeCache.getMessageDesc(CodeConstant.ERROR_9000.code)
    }


    @Test
    void test2() {
//        println DateUtil.parseDate("2017-01-01","yyyy-MM-dd")
//        println DateUtil.parseDate("2017-12-31 23:59:50")
//        println DateUtil.formateDate(new Date(),"")
//        println DateUtil.formateDateToChinese(new Date())
//        println DateUtil.getCurrentTimeMillis()
//        println DateUtil.getDateFirst(DateUtil.currentTimeMillis)
//        println DateUtil.getDateLast(DateUtil.currentTimeMillis)
//        println DateUtil.formateDate(DateUtil.addDay(DateUtil.getDate(),5),"")
//        println DateUtil.formateDate(DateUtil.addDay(DateUtil.getDate(),-4))
//        def date1=DateUtil.parseDate("2017-9-14 9:00:00")
//        def date2=DateUtil.parseDate("2017-9-13 10:00:00")
//        println DateUtil.dayDiff(date1.time,date2.time)
//
//        println DateUtil.dayDiff(DateUtil.getDate(),date2)

//        Calendar day1=Calendar.getInstance()
//        day1.add(Calendar.DAY_OF_YEAR,5)
//
//        Calendar day2=Calendar.getInstance()
//        println day1.compareTo(day2) //=1
//        day2.add(Calendar.DAY_OF_YEAR,10)
//        println day1.compareTo(day2) //-1

//        println DateUtil.formateDate(DateUtil.parseDate(1514822399000l))
//        println DateUtil.formateDate(1514822399000l)

//        Calendar calendar = Calendar.getInstance()
//        calendar.setTimeInMillis(1499529599000l)
//        println calendar.format("yyyy年MM月dd日 HH时mm分ss秒") //2017年07月08日 23时59分59秒
//
//        println DateUtil.formateDate(1499529599000l, "yyyy年M月d日 HH时mm分ss秒") //2017年7月8日 23时59分59秒
//
//        println DateUtil.formateDate(DateUtil.parseDate("2017-12-31 23:59:50"), "yyyy年M月d日 HH时mm分ss秒")
////2017年12月31日 23时59分50秒
//        println DateUtil.getMonth(1499529599000l)//7
//        println DateUtil.getMonth(DateUtil.parseDate("2017-12-31 23:59:50"))//12
//        println DateUtil.getMonth(DateUtil.parseDate("2017-01-01 23:59:50"))//1

        println DateUtil.formateDate(DateUtil.getDateFirstTime())
        println DateUtil.formateDate(DateUtil.getDateLastTime())
        println DateUtil.formateDate(DateUtil.getDateLastTime(1499524391000l))
        println DateUtil.formateDate(DateUtil.getDateFirstTime(1499524391000l))

    }


}
